#ifndef _TEXT_H_LULY_
#define _TEXT_H_LULY_
#include <string>
#include <vector>

#include "../Rect.h"
#include "Color.h"
#include "Font.h"

//待办：Text根据宽高自动换行

class Text {
 private:
  int width = 0;
  int height = 0;
  Font font;
  std::string str;  //所有字符(原始字符)

  std::string
      prostr;  //处理过的字符(根据宽高添加分行符)，只有调用了str_lines_update_byWH才会改变
  std::vector<std::string> str_lines;  //每一行字符（处理后的字符行，如\n分行）
  size_t maxLenPos = 0;  //最长的那行字符所在的下标
 private:
  void drawInOneLine(Font font, Color::RGBA color, std::string oneLineStr,
                     int x, int y, double scale, double angle);
  void drawAreaInOneLine(Rect area, Font font, Color::RGBA color,
                         std::string oneLineStr, int x, int y, double scale,
                         double angle);
  void drawAreaInOneLine1(Rect area, Rect cut, Rect dest, Font font,
                          std::string oneLineStr, Color::RGBA color,
                          double angle = 0);

 public:
  Text() : str("") {}
  Text(std::string str, Font font);

  void str_lines_update();

  void str_lines_update_byWH(int width,
                             int height);  //通过指定的宽高自动更新str_lines

  void init();
  void draw(Font font, Color::RGBA color, int x, int y, double scale,
            double angle);
  void drawArea(Rect area, Font font, Color::RGBA color, int x, int y,
                double scale, double angle);

  int getWidth() { return width; }
  int getHeight() { return height; }
  std::string& getTextStr() { return str; }
};

#endif